package GUI;

import processing.core.PImage;
import processing.core.PImage;


public class CloseButton extends Component {
	public boolean clicked;
	public boolean pressed;

	////////////////////////////////////////////////////////////////////////////////////////////////////
	public CloseButton()
	{
		super();
		width=11;
		height=11;
		index=0;
	}
	public void setIcon(String name)
	{
		if(label != null)
		{
			icon = GV.processing.loadImage(name);
		}
	}
	public void setLabel(String label){
		this.label=label;
	}
	public void draw()
	{
		GV.processing.textFont(GV.plotFont, 14);
		GV.processing.stroke(128);
		GV.processing.strokeWeight(1);
		GV.processing.fill(GV.textColor);
		GV.processing.line(x, y, x+width, y+height);
		GV.processing.line(x+width, y, x, y+height);

		int cx = x;
		int cy = y;

		GV.processing.textAlign(GV.processing.LEFT);

		if(icon != null)
		{
			GV.processing.image(icon, cx +120 + (index%2)*35, cy,35,35);
		}
		if(label!=null){
			GV.processing.text(label, cx +20, cy + 10);

		}

		if(mouseOver()) 
		{
			super.draw();
			if(GV.processing.mousePressed)
			{
				//gu.drawVGradient(x, y + height, width, -height, color(150, 150, 180), 80, color(150, 150, 180), 255, 0.8);    
				GV.gu.drawBox(x, y, width, height, 0, GV.processing.color(150, 150, 200), 255);
				GV.gu.drawBox(x, y, width, height, 1, GV.processing.color(150, 150, 200), 150);
				pressed = true;

				cx += 2;
				cy += 2;
			}
			else if(pressed)
			{
				pressed = false;
				if(clicked)
					clicked=false;
				else clicked=true;
			}
		}
		else
		{
			pressed = false;
		}

	}

	////////////////////////////////////////////////////////////////////////////////////////////////////
	PImage icon;
	String label;
	int index;

}
